using Godot;
using System;

public partial class AxeAbility : Node2D
{

	const int MAX_RADIUS = 100;
	public HitboxComponent hitboxComponent;

	Vector2 baseRotation =  Vector2.Right;

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		baseRotation = Vector2.Right.Rotated((float)(new Random().NextDouble()*Math.Tau));

		hitboxComponent = GetNode<HitboxComponent>("HitboxComponent");
		Tween tween = CreateTween();
		tween.TweenMethod(Callable.From<float>(TweenMethod),0.0,2.0,3);
		tween.TweenCallback(Callable.From(QueueFree));
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}

	public void TweenMethod(float rotations){
		float percent = rotations/2;
		float currentRadius = percent * MAX_RADIUS;
		Vector2 currentDirection = baseRotation.Rotated((float)(rotations*Math.Tau));

		Node2D player = GetTree().GetFirstNodeInGroup("player") as Node2D;
		if(player == null){
			return; 
		}
		GlobalPosition = player.GlobalPosition + ( currentDirection * currentRadius );
	}
}
